$pgv-icon-size: 1.375rem;
$pgv-item-padding-inline: 0.7rem;

.pgw-filter-bar {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  margin-bottom: 0.75rem;

  &::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: var(--form-input-border-radius);
    // TODO - var fallback can removed after baseline is moved >= 2.496
    border: var(
      --jenkins-border,
      2px solid color-mix(in srgb, var(--text-color-secondary) 10%, transparent)
    );
    box-shadow: var(--form-input-glow);
    transition: var(--standard-transition);
  }

  button {
    border-radius: 0.4rem;
    padding-inline: 0;
    width: 42px;

    &::before,
    &::after {
      inset: 5px;
    }
  }

  .jenkins-search {
    --search-bar-height: 2.625rem;

    input {
      border: none !important;
      box-shadow: none !important;
      background: none !important;
      padding: 0 0 0 var(--search-bar-height);
    }
  }

  &:hover {
    &::before {
      border-color: var(--input-border-hover);
    }
  }

  &:has(input:focus) {
    &::before {
      border-color: var(--focus-input-border);
      box-shadow: var(--form-input-glow--focus);
    }
  }
}

.pgv-tree {
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  margin: 0;
}

.pgv-tree-stage {
  position: relative;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.pgv-tree-item-container {
  position: relative;
  appearance: none;
  z-index: 0;
  font-weight: normal;
  border-radius: var(--form-input-border-radius);
  cursor: pointer;
  background: transparent;
  outline: none;
  border: none;

  &::before,
  &::after {
    position: absolute;
    content: "";
    inset: 0;
    z-index: -1;
    border-radius: inherit;
    transition: var(--standard-transition);
    pointer-events: none;
  }

  &::before {
    background-color: var(--item-background);
    border: var(--jenkins-border--subtle);
  }

  &::after {
    box-shadow: 0 0 0 0.5rem transparent;
  }

  &:focus-visible {
    outline: none;
  }

  &:not(:disabled) {
    &:hover,
    &:focus-visible,
    &[aria-describedby],
    &[aria-expanded="true"] {
      &::before {
        background-color: var(--item-background--hover);
      }
    }

    &:active {
      outline: none !important;
      z-index: 1;

      &::before {
        background-color: var(--item-background--active);
      }

      &:active {
        &::after {
          box-shadow: 0 0 0 0.25rem var(--item-box-shadow--focus);
        }
      }
    }

    &:has(.pgv-tree-item--active) {
      &::before {
        background-color: var(--item-background--active);
      }
    }

    &:focus-visible {
      &::after {
        box-shadow: 0 0 0 0.2rem var(--text-color) !important;
        opacity: 1 !important;
      }
    }
  }

  &:not(:hover, &:active, &:focus, &:has(.pgv-tree-item--active)) {
    &::before {
      border-color: transparent;
    }
  }
}

.pgv-tree-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  justify-content: start;
  align-items: center;
  text-decoration: none;
  color: var(--text-color);
  position: relative;
  padding: 0.5rem $pgv-item-padding-inline;

  mask-image: linear-gradient(
    90deg,
    white calc(100% - 3rem),
    transparent calc(100% - 2rem)
  );

  &:visited,
  &:link {
    color: inherit;
    text-decoration: none;
  }

  &--active {
    font-weight: 450;

    .pgv-status-icon {
      svg > * {
        stroke-width: 35px;
      }
    }
  }

  &__content {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: start;
    gap: 0.65rem;
    min-width: 0;
  }

  &__info {
    display: flex;
    flex-direction: row;
    gap: 0.65rem;
  }

  &__name,
  &__description {
    overflow: hidden;
    white-space: nowrap;
  }

  &__description {
    color: var(--text-color-secondary);
  }

  &__toggle {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    aspect-ratio: 1;
    transition: var(--standard-transition);
    appearance: none;
    background: none;
    padding: 0;
    border: none;
    cursor: pointer;
    color: var(--text-color-secondary);
    z-index: 1;

    &--active {
      rotate: 90deg;
    }

    svg {
      width: 1rem;
      height: 1rem;

      * {
        stroke-width: 42px;
      }
    }

    &:hover {
      color: var(--text-color);
    }
  }

  &--skeleton {
    pointer-events: none;
    color: var(--text-color-secondary) !important;
  }
}

.pgv-status-icon {
  display: flex;
  align-items: center;

  svg {
    width: $pgv-icon-size;
    height: $pgv-icon-size;
  }
}

.pgv-tree-children {
  position: relative;
  display: flex;
  flex-direction: column;
  padding-left: calc($pgv-item-padding-inline + $pgv-icon-size);

  &::before {
    content: "";
    position: absolute;
    top: 0.375rem;
    // TODO - var fallback can removed after baseline is moved >= 2.496
    left: calc(
      $pgv-item-padding-inline + ($pgv-icon-size / 2) -
        (var(--jenkins-border-width, 2px) / 2)
    );
    bottom: 0.375rem;
    // TODO - var fallback can removed after baseline is moved >= 2.496
    background-color: var(
      --jenkins-border-color,
      color-mix(in srgb, var(--text-color-secondary) 25%, transparent)
    );
    // TODO - var fallback can removed after baseline is moved >= 2.496
    width: var(--jenkins-border-width, 2px);
    border-radius: var(--form-input-border-radius);
  }
}
